package com.example.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.Date;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "onCreate");
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        //activity跳转
        findViewById(R.id.btn_go).setOnClickListener(v -> {
            Intent intent = new Intent(this, MainActivity2.class);
            Bundle bundle = new Bundle();
            bundle.putString("time", String.valueOf(new Date()));
            bundle.putString("content", "发送过来的消息");
            intent.putExtras(bundle);
            startActivity(intent);
        });
        findViewById(R.id.btn_phone).setOnClickListener(v->{
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_DIAL);
            String phoneNum = "12345";
            Uri uri = Uri.parse("tel:19911575278");
            intent.setData(Uri.parse("tel:19911575278"));
            startActivity(intent);
        });
        findViewById(R.id.btn_sms).setOnClickListener(v->{
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SENDTO);
            String phoneNum = "19911575278";
            Uri uri = Uri.parse("smsto:19911575278");
            intent.setData(uri);
            startActivity(intent);
        });
        findViewById(R.id.btn_otherApp).setOnClickListener(v->{
            Intent intent = new Intent();
            intent.setAction("android.intent.action.calculator");
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            startActivity(intent);
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG, "onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG, "onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d(TAG, "onRestart");
    }
}